package com.quanquan.store.controller;

import com.alibaba.fastjson.JSON;
import com.quanquan.store.entity.Test;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import utils.DateUtils;
import utils.DecriptUtils;
import utils.MD5Util;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @ClassName:TestController
 * @Description:TODO
 * @Author:xiongjunbao
 * @Date:2019/3/20 14:20
 * @Version 1.0
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @PostMapping("/tt")
    public String tt() {
        Test test = new Test();
        test.setAppId("BLH");
        test.setMobliePhone("15203997213");
        String jsonStr = JSON.toJSONString(test);
        String timeStamp = DateUtils.parseDate2Str("yyyyMMddHHmmss", new Date());
        String sb = new StringBuffer().append(jsonStr).append("D267B6465F5445EBA627DB4936DCE9AA").append(timeStamp).toString();
        System.out.println(sb);
        String ms5 = MD5Util.getMD5(sb, true, 32);
        return ms5;
    }

    @PostMapping("/test")
    public String test(String sb) {
        String ms5 = DecriptUtils.MD5(sb);
        return ms5;
    }

    public static int weekNum(String dateTime) throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date date = format.parse(dateTime);
        Calendar calendar = Calendar.getInstance();
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        calendar.setTime(date);
        return calendar.get(Calendar.WEEK_OF_YEAR);
    }

    public static void main(String[] args) throws ParseException {
//        System.out.println(weekNum("2019-12-31"));
//        System.out.println(new Date());
//
//        String dayTime = DateUtils.dateToString(new Date(), DateUtils.DATE).substring(8, 10);
//        System.out.println(dayTime);
//
//
//        Calendar c = Calendar.getInstance();
//
//        int count = 7;
//
//        List<String> dateList = new LinkedList<>();
//
//        for (int n = 0; n < 7; n++) {
//            c.setTime(new Date());
//            c.add(Calendar.DATE, -n);
//            Date d = c.getTime();
//            String date = DateUtils.dateToString(d, DateUtils.DATE);
//            dateList.add(date.substring(5,7));
//        }
//
//        System.out.println(dateList);
//
//
//        List<String> weekList = new LinkedList<>();
//        Calendar cl = Calendar.getInstance();
//        cl.setTime(new Date());
//        for (int n = 0; n < count; n++) {
//            if (n>0){
//                cl.add(Calendar.DATE, -7);
//            }else {
//                cl.add(Calendar.DATE,0);
//            }
//            int week = cl.get(Calendar.WEEK_OF_YEAR);
//            int year = cl.get(Calendar.YEAR);
//            if(week<cl.get(Calendar.WEEK_OF_YEAR)){
//                year+=1;
//            }
//            String time = null;
//            if (week<10){
//                time = year+"-0"+week;
//            }else {
//                time = year+"-"+week;
//            }
//            weekList.add(time);
//        }
//        System.out.println(weekList);
//
//
//        String dateString;
//        Calendar cal = Calendar.getInstance();
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
//        List<String> rqList = new ArrayList<>();
//        System.out.println("倒序前\n");
//        for (int i = 0; i < 6; i++) {
//            dateString = sdf.format(cal.getTime());
//
//            System.out.println("dateString"+dateString);
//
//            rqList.add(dateString.substring(0, 7));
////xfzeList.add(xfze);
//
//            cal.add(Calendar.MONTH, -1);
//        }

        Integer sendCount = 3;
        Integer cancelCount = 0;

        float num= (float)cancelCount/sendCount;
        DecimalFormat df = new DecimalFormat("0.00");//格式化小数
        String s = df.format(num*100);//返回的是String类型
        System.out.println(s);



        NumberFormat numberFormat = NumberFormat.getInstance();
        // 设置精确到小数点后2位
        numberFormat.setMaximumFractionDigits(2);
        String cancelRatio = numberFormat.format((float)cancelCount/(float)sendCount*100);
        System.out.println(cancelRatio+"%");


    }




}
